package com.muy.json.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.muy.json.utils.TimeUtils;
import com.muy.json.view.panel.PanelCompare;
import com.muy.json.view.window.redis.editor.JsonFileSystem;
import com.muy.json.view.window.redis.editor.JsonVirtualFile;
import org.jetbrains.annotations.NotNull;

/**
 * @Author jiyanghuang
 * @Date 2023/10/9 22:58
 */
public class OpenJsonEditorAction extends AnAction {

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        PanelCompare panelCompare = new PanelCompare(e.getProject());
        JsonVirtualFile jsonVirtualFile = new JsonVirtualFile("Json-" + TimeUtils.ymdhms(System.currentTimeMillis()), e.getProject(), panelCompare);

        ApplicationManager.getApplication().invokeLater(() -> {
            JsonFileSystem.getInstance(e.getProject()).openEditor(jsonVirtualFile);
        });
    }
}
